package com.sx.jys.ui.adapter

import android.content.Context
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.kunminx.binding_recyclerview.adapter.SimpleDataBindingAdapter
import com.sanxinsaas.nearstore.framework.util.click
import com.sx.jys.R
import com.sx.jys.app.framework.DiffUtilCallbacks
import com.sx.jys.app.net.bean.OrderBean
import com.sx.jys.databinding.ItemCkListBinding

class CkListAdapter(context: Context, val type: String) :
    SimpleDataBindingAdapter<OrderBean, ItemCkListBinding>(
        context,
        R.layout.item_ck_list, DiffUtilCallbacks().getItemCallBack()
    ) {
    override fun onBindItem(
        binding: ItemCkListBinding,
        item: OrderBean,
        holder: RecyclerView.ViewHolder
    ) {
        binding.data = item
        if ("4".equals(type)) {
            //委托
            binding.layoutWt1.visibility = View.VISIBLE
            binding.tvBack.visibility = View.VISIBLE
            binding.layoutWt2.visibility = View.VISIBLE
            binding.tvPc.visibility = View.GONE
            binding.tvMake.visibility = View.GONE
            binding.tvStatus.visibility = View.GONE
            binding.layoutYh.visibility = View.GONE
            binding.tvDetail.visibility = View.GONE
            binding.tvCreateTime.visibility = View.VISIBLE
            binding.layoutCk.visibility = View.GONE
            binding.layoutPrice.visibility=View.GONE
        } else if ("0".equals(type)) {
            //持仓中
            binding.tvBack.visibility = View.GONE
            binding.layoutWt1.visibility = View.GONE
            binding.layoutWt2.visibility = View.GONE
            binding.tvPc.visibility = View.VISIBLE
            item.isOneOrder?.let {
                if ("1".equals(it)) {
                    binding.tvMake.visibility = View.VISIBLE
                }else{
                    binding.tvMake.visibility = View.GONE
                }
            }
            binding.tvStatus.visibility = View.GONE
            binding.layoutYh.visibility = View.VISIBLE
            binding.tvDetail.visibility = View.VISIBLE
            binding.tvCreateTime.visibility = View.GONE
            binding.layoutCk.visibility = View.VISIBLE
            binding.layoutPrice.visibility=View.VISIBLE
        } else if ("1".equals(type)) {
            //历史订单
            binding.tvBack.visibility = View.GONE
            binding.layoutWt1.visibility = View.GONE
            binding.layoutWt2.visibility = View.GONE
            binding.tvPc.visibility = View.GONE
            binding.tvMake.visibility = View.GONE
            binding.tvStatus.visibility = View.VISIBLE
            binding.layoutYh.visibility = View.VISIBLE
            binding.tvDetail.visibility = View.VISIBLE
            binding.tvCreateTime.visibility = View.GONE
            binding.layoutCk.visibility = View.VISIBLE
            binding.layoutPrice.visibility=View.GONE
        } else if ("5".equals(type)) {
            //已取消
            binding.tvBack.visibility = View.GONE
            binding.layoutWt1.visibility = View.GONE
            binding.layoutWt2.visibility = View.GONE
            binding.tvPc.visibility = View.GONE
            binding.tvMake.visibility = View.GONE
            binding.tvStatus.visibility = View.GONE
            binding.layoutYh.visibility = View.GONE
            binding.tvDetail.visibility = View.GONE
            binding.tvCreateTime.visibility = View.GONE
            binding.layoutCk.visibility = View.VISIBLE
            binding.layoutPrice.visibility=View.GONE
        }
        binding.tvPc.click {
            mOnItemClickListener.onItemClick(it.id, item, holder.bindingAdapterPosition)
        }
        binding.tvMake.click {
            mOnItemClickListener.onItemClick(it.id, item, holder.bindingAdapterPosition)
        }
        binding.tvBack.click {
            mOnItemClickListener.onItemClick(it.id, item, holder.bindingAdapterPosition)
        }
    }
}